package com.chen.spikemall.service.impl;

import com.chen.spikemall.bean.CommonOrder;
import com.chen.spikemall.exception.NoInventoryException;
import com.chen.spikemall.repository.OrderDataTableRepository;
import com.chen.spikemall.service.GoodsService;
import com.chen.spikemall.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;


@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private OrderDataTableRepository orderDataTableRepository;

    @Override
    public String createOrder(String account, String GoodsNo) throws NoInventoryException {

        goodsService.goodsStoreValueDecrease(GoodsNo);

        CommonOrder commonOrder = new CommonOrder();

        String orderNo = UUID.randomUUID().toString();
        commonOrder.setOrderNo(orderNo);

        commonOrder.setSellerAccount(account);
        commonOrder.setGoodsNo(GoodsNo);

        orderDataTableRepository.save(commonOrder);

        return orderNo;
    }
}
